// 1.默认导入material风格的组件库
import 'package:flutter/material.dart';

class MyApp13 extends StatelessWidget {
  const MyApp13({super.key});

  List<Widget> getList() {
    // List<Widget> list = [];
    // for (var i = 0; i < 20; i++) {
    //   list.add(Container(
    //     width: double.infinity,
    //     height: 100,
    //     margin: const EdgeInsets.all(10),
    //     alignment: Alignment.center,
    //     decoration: BoxDecoration(
    //       borderRadius: BorderRadius.circular(35),
    //       color: Colors.blue,
    //     ),
    //     child: Text(
    //       '我是第$i个item',
    //       style: const TextStyle(color: Colors.white),
    //     ),
    //   ));
    // }
    // return list;
    return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map((int value) {
      return Container(
        width: double.infinity,
        height: 100,
        margin: const EdgeInsets.all(10),
        alignment: Alignment.center,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(35),
          color: Colors.blue,
        ),
        child: Text(
          '我是第$value个item',
          style: const TextStyle(color: Colors.white),
        ),
      );
    }).toList();
  }

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    // 3.创建一个MaterialApp组件（指定应用整体的UI风格：material风格）
    return Scaffold(
        // 1.1 导航
        appBar: AppBar(
          title: const Text('ListView组件'),
          backgroundColor: Colors.pink,
        ),
        // 1.2 主体内容
        body: ListView(children: getList()));
  }
}
